<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // Person.prototype.name = "han";  //祖先上有一个 name 属性
    // function Person(){
    //     //...
    // }
    // var person = new Person();  //  后代会继承祖先的属性
    // console.log(person);  // 访问是一个空的属性
    // console.log(person.name); //继承祖先的name属性，可以访问到

/*
    Person.prototype.lastName = "宝马";
    function Person(name){
        this.name = name;
    }
    var person = new Person("hanyun");
    person.lastName = "hanfei";//修改原型，执行后他自己多了一个lastName: "hanfei"，这种事给自己增加属性，
    // 想要修改person.prototype.lastName = "hanfei";
    console.log(person); //Person {name: "hanyun", lastName: "hanfei"}
    console.log(person.lastName); //hanfei  在这里访问的是他自己身上的
    person.address = "摆龙";
    console.log(person.address);
    delete person.address;
    Person.prototype.height = 1400;//给原型增加属性
    console.log(person.height);
    Person.prototype.height = 1600;//给原型修改属性
    console.log(person.height);
    delete Person.prototype.height;//删除原型属性

*/

/*
    Person.prototype.name = "sunny";
    function Person(){

    }
    Person.prototype.name = "cherry";
    var person = new Person();
    console.log(person.name);  //cherry
    Person.prototype.name = "han";
    console.log(person.name);  //han

    //注意啦

    Person.prototype = {//相当于一次大换血
        name : "prototype改成一个新的对象"
    };
    console.log(person.name);  //han
*/


/*
    //其实就想这个一样，把它换一下而已
    var obj = {name : "han"};
    var obj1 = obj;
    obj = {name : "wei"};
    console.log(obj1);  //var obj = {name : "han"};
    //换成上面的
    Person.prototype = {name : "a"};
    __proto__ = Person.prototype;
    Person.prototype = {name : "b"}
    console.log(__proto__);//{name : "a"};

 */

    Person.prototype.name = "a";
    function Person(){
        //var this = {__proto__:Person.prototype}
    }
    //这行代码是在---new---之前
    Person.prototype = {
        name : "b"
    };
    var person = new Person(); //---new---出现，Person()开始执行产生Person函数中的 var this = {}; return this
    console.log(person.name); //name = "b"


</script>

</body>
</html>
